package com.example.w.common.pattern;

import com.example.w.common.pojo.Order;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component("cashBack")
public class CashBackPricingStrategy implements PricingStrategy{

    @Value("${pricingStrategy.backLimit}")
    private BigDecimal limit;
    @Value("${pricingStrategy.backCash}")
    private BigDecimal back;

    @Override
    public BigDecimal getPricingTotal(Order order) {
        BigDecimal total = order.getTotal();
        return total.compareTo(limit) >= 0?
               total.subtract(back) : total;
    }
}
